Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / desktopApp / src / main / kotlin / org / meshtastic / desktop / radio / DesktopMessageQueue.kt

Displaying Raw • Download

desktopApp/src/main/kotlin/org/meshtastic/desktop/radio/DesktopMessageQueue.kt fix/qr-error-correction (7b45f84f) Text, 2.98 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.desktop.radio

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CancellationException
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.SupervisorJob
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787org.meshtastic.core.model.ConnectionState
Tff7b72import T7ee787org.meshtastic.core.model.MessageStatus
Tff7b72import T7ee787org.meshtastic.core.repository.MessageQueue
Tff7b72import T7ee787org.meshtastic.core.repository.PacketRepository
Tff7b72import T7ee787org.meshtastic.core.repository.PersistedPacketId
Tff7b72import T7ee787org.meshtastic.core.repository.RadioController

T8b949e/**
* Desktop implementation of [MessageQueue].
*
* Unlike Android which uses WorkManager to ensure delivery across app lifecycles, Desktop immediately delegates to the
* active controller to send the message.
*/
Tff7b72class T56d364DesktopMessageQueueTb4b4b4(
Tff7b72private Tff7b72val Te6edf3packetRepositoryTb4b4b4: Te6edf3PacketRepositoryTb4b4b4,
Tff7b72private Tff7b72val Te6edf3radioControllerTb4b4b4: Te6edf3RadioControllerTb4b4b4,
Te6edf3dispatchersTb4b4b4: Te6edf3CoroutineDispatchersTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3MessageQueue Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3scope Tff7b72= Te6edf3CoroutineScopeTb4b4b4(Te6edf3SupervisorJobTb4b4b4(Tb4b4b4) Tff7b72+ Te6edf3dispatchersTb4b4b4.Te6edf3ioTb4b4b4)

Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffenqueueTb4b4b4(Te6edf3persistedIdTb4b4b4: Te6edf3PersistedPacketIdTb4b4b4) Tb4b4b4{
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3persistedIdTb4b4b4.Te6edf3uuid Tff7b72<Tff7b72= T79c0ff0LTb4b4b4) Tff7b72returnTf0883e@launch

T8b949e// Verify we are connected before attempting to send to avoid unnecessary Exception bubbling
Tff7b72if Tb4b4b4(Te6edf3radioControllerTb4b4b4.Te6edf3connectionStateTb4b4b4.Te6edf3value Tff7b72!Tff7b72= Te6edf3ConnectionStateTb4b4b4.Te6edf3ConnectedTb4b4b4) Tb4b4b4{
T8b949e// In a real desktop environment, we might want a background loop to retry queued messages.
T8b949e// For now, it will retry when connection is re-established (handled by
T8b949e// MeshConnectionManager.onRadioConfigLoaded).
Tff7b72returnTf0883e@launch
Tb4b4b4}

Tff7b72val Te6edf3claimed Tff7b72= Te6edf3packetRepositoryTb4b4b4.Te6edf3claimQueuedPacketTb4b4b4(Te6edf3persistedIdTb4b4b4) Tff7b72?: Tff7b72returnTf0883e@launch
Tff7b72if Tb4b4b4(Te6edf3claimedTb4b4b4.Te6edf3packetTb4b4b4.Te6edf3status Tff7b72!Tff7b72= Te6edf3MessageStatusTb4b4b4.Te6edf3QUEUEDTb4b4b4) Tff7b72returnTf0883e@launch

Tff7b72try Tb4b4b4{
Te6edf3radioControllerTb4b4b4.Te6edf3sendMessageTb4b4b4(Te6edf3claimedTb4b4b4.Te6edf3packetTb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to send packet Tffd700${Te6edf3claimedTb4b4b4.Te6edf3packetTb4b4b4.Te6edf3idTffd700}Ta5d6ff, re-queuingTa5d6ff" Tb4b4b4}
Te6edf3packetRepositoryTb4b4b4.Te6edf3rollbackEnroutePacketTb4b4b4(Te6edf3claimedTb4b4b4.Te6edf3idTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3e Tff7b72is Te6edf3CancellationExceptionTb4b4b4) Tff7b72throw Te6edf3e
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s